﻿using System;
using System.Web.Script.Serialization;
using System.Collections.Generic;

/// <summary>
///TreeItem 的摘要说明
/// </summary>
public class TreeItem
{
    public TreeItem()
    {
        showcheck = true;
        checkstate = 0;
        complete = true;
        isexpand = false;
    }

    #region 属性
    /// <summary>
    /// 项目ID
    /// </summary>
    public string id { get; set; }
    /// <summary>
    /// 项的文本
    /// </summary>
    public string text { get; set; }
    /// <summary>
    /// 项的值
    /// </summary>
    public string value { get; set; }
    /// <summary>
    /// 是否显示选择框
    /// </summary>
    public bool showcheck { set; get; }

    /// <summary>
    /// 子节点是否展开
    /// </summary>
    public bool isexpand { set; get; }

    /// <summary>
    /// 子节点选择框的状态
    /// </summary>
    public int checkstate { get; set; }
    /// <summary>
    /// 是否有子节点
    /// </summary>
    public bool hasChildren { set; get; }
    /// <summary>
    /// 是否完成（用于区分是否要异步load数据）
    /// </summary>
    public bool complete { get; set; }

    /// <summary>
    /// 子节点列表
    /// </summary>
    public List<TreeItem> ChildNodes { get; set; }

    #endregion 属性

    #region 方法
    /// <summary>
    /// 生成 JSON 字符串，
    /// </summary>
    /// <returns></returns>
    public string ToJsonString()
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();
        string sJson = jss.Serialize(this);
        return "var treedata=[" + sJson + "];";
    }

    #endregion 方法
}
